<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>
<script>
    (function(){
        function Observer(){
            this.obj = {};
            this.on =function(type,handler){
                this.obj[type]= this.obj[type]||[];
                this.obj[type].push(handler);
            }
            this.emit = function(type,msg){
                this.obj[type] &&
                this.obj[type].forEach((item)=>{
                    item(msg);
                })
            }
        }
        window.Observer = Observer;
    })()
    var os = new Observer();
    os.on('lijiaqi',function(msg){
        console.log('李莉 收到了来自lijiaqi得消息' + msg);
    })
    os.on('lijiaqi',function(msg){
        console.log('李里 收到了来自lijiaqi得消息' + msg);
    })
    os.on('lijiaqi',function(msg){
        console.log('莉莉 收到了来自lijiaqi得消息' + msg);
    })
    os.on('weiya',function(msg){
        console.log('李丽 收到了来自weiya得消息' + msg);
    })
    os.on('weiya',function(msg){
        console.log('丽丽 收到了来自weiya得消息' + msg);
    })
    console.log(os);
    os.emit('lijiaqi','本周六补课')
</script>